package com.mall.service;

import com.mall.mapper.registerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;

@Service
@Transactional
public class registerService {
    @Autowired
    private registerMapper registerMapper;
    public void register(String account, String password, String nickName) {
        if(registerMapper.getLoginByAccount(account)!=null) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "账号已注册");
        }
        if(registerMapper.getLoginByNickName(nickName)!=null) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "昵称已被使用");
        }
        registerMapper.register(account, password, nickName);
    }
}
